package com.dat255.tentatime;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.dat255.internalstorage.*;
import android.widget.ListView;
import android.widget.TextView;

//TODO: make a base class for fav and res, they ARE very similar
public class FavouriteActivity extends ListActivity {
	
	private TextView title,titleempty;
	private FavoritesManagement fav_manage;
	private ExamAdapter adapter;

	 /** 
     * Called when the activity is first created. 
     * This method will also add all the exams from the previous activity
     * and display it on the listview
     */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		// set the layout for this activity
		setContentView(R.layout.result);
		
		//make the textview in the layout editable
		title = (TextView) findViewById(R.id.listName);
		titleempty = (TextView) findViewById (android.R.id.empty);
		titleempty.setText("No Favorites!");
		
		
		//change the title
		title.setText("Favourites");
		
		
		//create a favourite management object, the list will only handle 15 rows
		fav_manage = new FavoritesManagement(this,15);
		
		adapter = new ExamAdapter(this, R.layout.result_row, fav_manage.listOfFavorites());
		//Update the view with the favorite list
		setListAdapter(adapter);
		
	}
	/**
	 * If the user has selected an exam, a new activity with all the details of the exam
	 * will be started
	 */
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
	
		super.onListItemClick(l, v, position, id);
				//Get the selected exam from the list
				Exam o = (Exam) this.getListAdapter().getItem(position);
				Intent examIntent = new Intent(FavouriteActivity.this, ShowExamActivity.class);
				//Move the selected exam object to next activity
				examIntent.putExtra(
						FavouriteActivity.this.getString(R.string.keySelectedExam), o);
				//Menu options for delete favourite will be disabled
				examIntent.putExtra(
						FavouriteActivity.this.getString(R.string.keyMenuEnable), true);
				//Start the activivity
				FavouriteActivity.this.startActivity(examIntent); 
	}

	

}
